package com.bbx.taxi.client.Activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.graphics.Typeface;
import android.media.Image;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import butterknife.InjectView;

import com.bbx.taxi.client.Activity.Base.BaseBBXActivity;
import com.bbx.taxi.client.Adapter.FareDetailsAdapter;
import com.bbx.taxi.client.Adapter.FareDetailsAdapter;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Extra.FareDetailsMsg;
import com.bbx.taxi.client.Fragment.OfficialFragment;
import com.bbx.taxi.client.Util.FormatUtil;
import com.bbx.taxi.official.R;

/** 
 * @Path com.bbx.taxi.client.Activity.FareDetailsActivity.java
 * @Author 严旭文
 * @Date 2016-2-29 上午11:03:55
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 车费预估，跟分摊信息
 */
public class FareDetailsActivity  extends BaseBBXActivity{
	@InjectView(R.id.layout_estimate_price)
	RelativeLayout layout_estimate_price;
	@InjectView(R.id.tv_estimate_price)
	TextView tv_estimate_price;
	@InjectView(R.id.lv_paydetail)
	ListView lv_paydetail;
	@InjectView(R.id.iv_icon)
	ImageView iv_icon;
	@InjectView(R.id.tv_car)
	TextView tv_car;
	/**支付费用明细列表*/
	private List<Map<String, String>> list=new ArrayList<Map<String,String>>();
	private FareDetailsAdapter mFareDetailsAdapter;
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_fare_detail);
		super.onCreate(savedInstanceState);
        setTitle(R.string.title_estimate);
	}
	@Override
	protected void initView() {
		layout_estimate_price.setVisibility(View.VISIBLE);

		
	}

	@Override
	protected void initData() {
		mFareDetailsAdapter=new FareDetailsAdapter(context, list);
		Intent intent =getIntent();
		Bundle mBundle = intent.getExtras();
		if(intent.getExtras()!=null){
			int type=Integer.parseInt(mBundle.getString(FareDetailsMsg.MSG_VTYPE));
			int position = 0;
			for (int i = 0; i < Value.list_vtype.length; i++) {
				if (type == Value.list_vtype[i]) {
					position = i;
					break;
				}
			}
			iv_icon.setImageDrawable(context.getResources().getDrawable(OfficialFragment.icon_car_down[position]));
			String typetitle=mBundle.getString(FareDetailsMsg.MSG_VTYPETITLE);
			String[] split_vtypetitle = typetitle.split(" ");
			if (split_vtypetitle != null && split_vtypetitle.length >= 2) {
				tv_car.setText(
						split_vtypetitle[0] + "(" + split_vtypetitle[1] + ")");
				tv_car.setTextColor(getResources().getColor(R.color.blue));
			}
			
			tv_estimate_price.setText(mBundle.getString(FareDetailsMsg.MSG_PRICE)); 
			tv_estimate_price.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/num.ttf"));
			// 添加起步价
			addPayDetail(getString(R.string.start_price), String.format(getString(R.string.price), mBundle.getString(FareDetailsMsg.MSG_START_PRICE)));
			// 添加里程费
			addPayDetail(getString(R.string.off_distance_price),String.format(getString(R.string.price), mBundle.getString(FareDetailsMsg.MSG_MILEPRICE))
					+"("+mBundle.getString(FareDetailsMsg.MSG_MILE)+")公里");
			// 添加时间费
			addPayDetail(getString(R.string.time_price2), String.format(getString(R.string.price), mBundle.getString(FareDetailsMsg.MSG_MINUTEPRICE))+"("+mBundle.getString(FareDetailsMsg.MSG_MINUTE)+")分钟");
		}
		lv_paydetail.setAdapter(mFareDetailsAdapter);
		
	}
	/**
	 * 添加费用明细列表
	 */
	public void addPayDetail(String name, String money) {
		Map<String, String> map = new HashMap<String, String>();
		map.put(FareDetailsAdapter.PAYDETAIL_NAME, name);
		map.put(FareDetailsAdapter.PAYDETAIL_MONEY, money);
		list.add(map);
	}
	   /**
     * 设置费用明细列表
     */
    public void setPayDetailList(List<Map<String, String>> list){
    	this.list.clear();
    	this.list.addAll(list);
    	mFareDetailsAdapter.notifyDataSetChanged();
    }

}
